from flask import session,current_app,g,jsonify
from info.models import User


import functools
def login_required(f):
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id')
        # 1.2
        # 如果有user_id, 根据id查询mysql，获取用户信息
        user = None
        try:
            user = User.query.get(user_id)
        except Exception as e:
            current_app.logger.error(e)
        #使用g对象，来临时存储用户信息
        g.user = user
        return f(*args,**kwargs)
    return wrapper



